#include "command.h"
addNewNodeCommand::addNewNodeCommand()
{

}
addNewNodeCommand::addNewNodeCommand(nodePath cn,NewNodeArgs ar,DataManipulator* da):containerNodePath(cn),args(ar),datamanipulator(da)
{

}
addNewNodeCommand:: ~addNewNodeCommand()
{
	//delete datamanipulator;
}
void addNewNodeCommand::redo()
    {
       NodeType nodetype=args.nodetype;
       datamanipulator->ToRoot();
	   bool firstchild=false;
	   int index1;
	   int index2;
       for (int i=0;i!=containerNodePath.path.count();i++)
           datamanipulator->EnterIntoChild(containerNodePath.path[i]);
       switch(nodetype)
	   {
	   case movieClipNode:
           datamanipulator->NewMovieClip();
           index=datamanipulator->ChildrenCount()-1;
           //index=index*1;
           datamanipulator->EnterIntoChild(index);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
           datamanipulator->EscapeToParent();
           break;
	   case recNode:
		   if(datamanipulator->CurrentNodeType()==MovieClip)
			   datamanipulator->BeginDrawingAt();
           /*bool firstchild=false;
           int index1;
           int index2;*/
           if(datamanipulator->ChildrenCount()==0)
           {
              firstchild=true;
              index1=datamanipulator->IndexOfCurrent();
           }
		   datamanipulator->AddRect(args.width,args.height);
           index2=datamanipulator->ChildrenCount()-1;
           datamanipulator->EnterIntoChild(index2);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
           datamanipulator->EscapeToParent();
           index=firstchild?index1:index2;
           break;
       case pathNode:
           if(datamanipulator->CurrentNodeType()==MovieClip)
			   datamanipulator->BeginDrawingAt();
          /* firstchild=false;*/
           if(datamanipulator->ChildrenCount()==0)
           {
              firstchild=true;
              index1=datamanipulator->IndexOfCurrent();
           }
           datamanipulator->BeginPath();
           for(int i=0;i!=args.pointsForPathNode.count();i++)
           {
               datamanipulator->AddLinearPoint(args.pointsForPathNode[i]);
           }
           datamanipulator->EndPath();
           index2=datamanipulator->ChildrenCount()-1;
           datamanipulator->EnterIntoChild(index2);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
           datamanipulator->EscapeToParent();
           index=firstchild?index1:index2;
           break;
	   case eclipseNode:
		    if(datamanipulator->CurrentNodeType()==MovieClip)
			   datamanipulator->BeginDrawingAt();
           /*bool firstchild=false;
           int index1;
           int index2;*/
           if(datamanipulator->ChildrenCount()==0)
           {
              firstchild=true;
              index1=datamanipulator->IndexOfCurrent();
           }
		   datamanipulator->AddEclipse(args.width,args.height);
           index2=datamanipulator->ChildrenCount()-1;
           datamanipulator->EnterIntoChild(index2);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
           datamanipulator->EscapeToParent();
           index=firstchild?index1:index2;
           break;
	   case wordShapNode:
           if(datamanipulator->CurrentNodeType()==MovieClip)
			   datamanipulator->BeginDrawingAt();
           /*firstchild=false;*/
           if(datamanipulator->ChildrenCount()==0)
           {
              firstchild=true;
              index1=datamanipulator->IndexOfCurrent();
           }
           /*QImage* qim=new QImage(args.UrlForPicNode);*/
		   datamanipulator->AddText(args.wordContent);
		   //datamanipulator->AddPicture(args.UrlForPicNode);
		   index2=datamanipulator->ChildrenCount()-1;
           datamanipulator->EnterIntoChild(index2);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
		   datamanipulator->WordFont(args.font);
           datamanipulator->EscapeToParent();
           index=firstchild?index1:index2;
           break;
	   case pictureNode:
           if(datamanipulator->CurrentNodeType()==MovieClip)
			   datamanipulator->BeginDrawingAt();
           /*firstchild=false;*/
           if(datamanipulator->ChildrenCount()==0)
           {
              firstchild=true;
              index1=datamanipulator->IndexOfCurrent();
           }
           /*QImage* qim=new QImage(args.UrlForPicNode);*/
		   datamanipulator->AddPicture(args.UrlForPicNode);
		   index2=datamanipulator->ChildrenCount()-1;
           datamanipulator->EnterIntoChild(index2);
           datamanipulator->SetNodeProperty(posx,this->args.position.x());
           datamanipulator->SetNodeProperty(posy,this->args.position.y());
           datamanipulator->EscapeToParent();
           index=firstchild?index1:index2;
           break;
       default:
           break;
	   }
	   this->datamanipulator->Update();
    }
void addNewNodeCommand::undo()
{
     //NodeType nodetype=args.nodetype;
      datamanipulator->ToRoot();
      for (int i=0;i!=containerNodePath.path.count();i++)
         datamanipulator->EnterIntoChild(containerNodePath.path[i]);
      datamanipulator->RemoveNodeAt(index);
	  this->datamanipulator->Update();
}
setPropertyCommand::setPropertyCommand()
{
}
setPropertyCommand::setPropertyCommand(nodePath p,SetArgs a,DataManipulator* da):currentNodePath(p),args(a),dataManipulator(da)
{

}
setPropertyCommand::~setPropertyCommand()
{
	//delete dataManipulator;
}
void setPropertyCommand::redo()
{
        dataManipulator->ToRoot();
        for (int i=0;i!=currentNodePath.path.count();i++)
            dataManipulator->EnterIntoChild(currentNodePath.path[i]);
        oldargs.time=args.time;
        oldargs.propertype=args.propertype;
        oldargs.value=dataManipulator->GetNodeProperty(args.propertype,args.time);
		oldargs.ease=dataManipulator->GetNodePropertyEase(args.propertype,args.time);
        dataManipulator->SetNodeProperty(args.propertype,args.value,args.time,args.ease);
		this->dataManipulator->EscapeToParent();
		this->dataManipulator->Update();
}
void setPropertyCommand::undo()
{
        dataManipulator->ToRoot();
        for (int i=0;i!=currentNodePath.path.count();i++)
            dataManipulator->EnterIntoChild(currentNodePath.path[i]);
        dataManipulator->SetNodeProperty(oldargs.propertype,oldargs.value,oldargs.time,oldargs.ease);
		this->dataManipulator->EscapeToParent();
		this->dataManipulator->Update();
}
deleteNodeCommand::deleteNodeCommand()
{
}
deleteNodeCommand::deleteNodeCommand(nodePath np,DataManipulator* da):containerPath(np),datamanipulator(da)
{
		
      int tmp=containerPath.path[containerPath.path.count()-1];
	  deleteIndex=tmp;
	  containerPath.path.pop_back();


}
deleteNodeCommand::~deleteNodeCommand()
{
	//delete datamanipulator;
}
void deleteNodeCommand::redo()
    {
        datamanipulator->ToRoot();
        for (int i=0;i!=containerPath.path.count();i++)
            datamanipulator->EnterIntoChild(containerPath.path[i]);
		const DisplayNode* tmp=datamanipulator->ChildPtAt(deleteIndex);
		eNodeType nt=tmp->NodeType();
		switch(nt){
		case Rect:
			{
				old=new RectNode(*((RectNode*)tmp));
				break;
			}
		case Eclipse:
			{
				old=new EclipseNode(*((EclipseNode*)tmp));
				break;
			}
			case Path:
			{
				old=new PathNode(*((PathNode*)tmp));
				break;
			}
			case Picture:
			{
				old=new PictureNode(*((PictureNode*)tmp));
				break;
			}
			case Symbol:
			{
				old=new SymbolNode(*((SymbolNode*)tmp));
				break;
			}
			case WordShape:
			{
				old=new WordShapeNode(*((WordShapeNode*)tmp));
				break;
			}
			case MovieClip:
			{
				old=new MovieClipNode(*((MovieClipNode*)tmp));
				break;
			}
			default:
				break;
		}
		/*old=new ContainerNode();
		old = datamanipulator->ChildPtAt(deleteIndex);*/
        datamanipulator->RemoveNodeAt(deleteIndex);
		this->datamanipulator->Update();
 }
void deleteNodeCommand::undo()
{
	datamanipulator->ToRoot();
    for (int i=0;i!=containerPath.path.count();i++)
        datamanipulator->EnterIntoChild(containerPath.path[i]);
	datamanipulator->AddNodeAt(old,deleteIndex);
	this->datamanipulator->Update();
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}

setStaticPropertyCommand::setStaticPropertyCommand()
{
}
setStaticPropertyCommand::~setStaticPropertyCommand()
{
}
setStaticPropertyCommand::setStaticPropertyCommand(nodePath np,SetStaticProperArgs a,DataManipulator* da):currentNodePath(np),newArgs(a),datamanipulator(da)
{
}
void setStaticPropertyCommand::redo()
{
	datamanipulator->ToRoot();
    for (int i=0;i!=currentNodePath.path.count();i++)
		datamanipulator->EnterIntoChild(currentNodePath.path[i]);
	oldArgs.sType=newArgs.sType;
	switch(newArgs.sType){
	case lineWidth:
		{
			QPen currentPen=this->datamanipulator->CurrentPen();
			oldArgs.linewidth=currentPen.width();
			currentPen.setWidth(newArgs.linewidth);
			break;
		}
	case lineColor:
		{
			QPen currentPen=this->datamanipulator->CurrentPen();
			oldArgs.linecolor=currentPen.color();
			currentPen.setColor(newArgs.linecolor);
			break;
		}
	case fillColor:
		{
			QBrush currentBrush=this->datamanipulator->CurrentBrush();
			oldArgs.fillcolor=currentBrush.color();
			currentBrush.setColor(newArgs.fillcolor);
			break;
		}
	case nodeName:
		{
			oldArgs.nodename=this->datamanipulator->CurrentNodeName();
			this->datamanipulator->SetCurrentNodeName(newArgs.nodename);
			break;
		}
	case wordFont:
		{
			oldArgs.wordfont=((WordShapeNode*)(this->datamanipulator->CurrentPt()))->Font();
			this->datamanipulator->WordFont(newArgs.wordfont);
			break;
		}
	case wordContent:
		{
			oldArgs.wordcontent=((WordShapeNode*)(this->datamanipulator->CurrentPt()))->Text();
			this->datamanipulator->WordText(newArgs.wordcontent);
			break;
		}
	default:
		break;

	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();

}

void setStaticPropertyCommand::undo()
{
	datamanipulator->ToRoot();
    for (int i=0;i!=currentNodePath.path.count();i++)
		datamanipulator->EnterIntoChild(currentNodePath.path[i]);
	oldArgs.sType=newArgs.sType;
	switch(newArgs.sType){
	case lineWidth:
		{
			QPen currentPen=this->datamanipulator->CurrentPen();
			currentPen.setWidth(oldArgs.linewidth);
			break;
		}
	case lineColor:
		{
			QPen currentPen=this->datamanipulator->CurrentPen();
			currentPen.setColor(oldArgs.linecolor);
			break;
		}
	case fillColor:
		{
			QBrush currentBrush=this->datamanipulator->CurrentBrush();
			currentBrush.setColor(oldArgs.fillcolor);
			break;
		}
	case nodeName:
		{
			this->datamanipulator->SetCurrentNodeName(oldArgs.nodename);
			break;
		}
	case wordFont:
		{
			this->datamanipulator->WordFont(oldArgs.wordfont);
			break;
		}
	case wordContent:
		{
			this->datamanipulator->WordText(oldArgs.wordcontent);
			break;
		}
	default:
		break;

	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}

nodeConvertCommand::nodeConvertCommand()
{
}
nodeConvertCommand::nodeConvertCommand(nodePath np,NodeType ty,DataManipulator* da):currentNodePath(np),newType(ty),datamanipulator(da)
{
}
nodeConvertCommand::~nodeConvertCommand()
{
}
void nodeConvertCommand::redo()
{
	datamanipulator->ToRoot();
    for (int i=0;i!=currentNodePath.path.count()-1;i++)
		datamanipulator->EnterIntoChild(currentNodePath.path[i]);
	int index=currentNodePath.path.at(currentNodePath.path.count()-1);
	const DisplayNode* tmp=this->datamanipulator->ChildPtAt(index);
	eNodeType nt=tmp->NodeType();
		switch(nt){
		case Rect:
			{
				oldNode=new RectNode(*((RectNode*)tmp));
				break;
			}
		case Eclipse:
			{
				oldNode=new EclipseNode(*((EclipseNode*)tmp));
				break;
			}
			case Path:
			{
				oldNode=new PathNode(*((PathNode*)tmp));
				break;
			}
			case Picture:
			{
				oldNode=new PictureNode(*((PictureNode*)tmp));
				break;
			}
			case Symbol:
			{
				oldNode=new SymbolNode(*((SymbolNode*)tmp));
				break;
			}
			case WordShape:
			{
				oldNode=new WordShapeNode(*((WordShapeNode*)tmp));
				break;
			}
			case MovieClip:
			{
				oldNode=new MovieClipNode(*((MovieClipNode*)tmp));
				break;
			}
			default:
				break;
		}
	oldType=(NodeType)(this->datamanipulator->CurrentNodeType());
	switch(newType)
	{
	case pictureNode:
		this->datamanipulator->ConvertToImage(index);
		break;
	case movieClipNode:
		this->datamanipulator->ConvertToMovieClip(index);
		break;
	case pathNode:
		this->datamanipulator->ConvertToPath(index);
		break;
	default:
		break;
	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
void nodeConvertCommand::undo()
{
	datamanipulator->ToRoot();
    for (int i=0;i!=currentNodePath.path.count()-1;i++)
		datamanipulator->EnterIntoChild(currentNodePath.path[i]);
	int index=currentNodePath.path.at(currentNodePath.path.count());
	this->datamanipulator->RemoveNodeAt(index);
	this->datamanipulator->AddNodeAt(oldNode,index);
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
swapLayerCommand::swapLayerCommand()
{
}
swapLayerCommand::swapLayerCommand(nodePath cp,int originali,int aimindex,DataManipulator* da):containerNodePath(cp),originalIndex(originali),destIndex(aimindex),datamanipulator(da)
{
}
swapLayerCommand::~swapLayerCommand()
{

}
void swapLayerCommand::redo()
{
	 datamanipulator->ToRoot();
     for (int i=0;i!=containerNodePath.path.count();i++)
        datamanipulator->EnterIntoChild(containerNodePath.path[i]);
	 this->datamanipulator->ExchangeNodeAt(originalIndex,destIndex);
	 //this->datamanipulator->EscapeToParent();
	//this->datamanipulator->Update();
}
void swapLayerCommand::undo()
{
	datamanipulator->ToRoot();
     for (int i=0;i!=containerNodePath.path.count();i++)
        datamanipulator->EnterIntoChild(containerNodePath.path[i]);
	 this->datamanipulator->ExchangeNodeAt(destIndex,originalIndex);
	 this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
addCurvePointCommand::addCurvePointCommand()
{
}
addCurvePointCommand::addCurvePointCommand(nodePath np,AddPointArgs a,DataManipulator* da):path(np),args(a),datamanipulator(da)
{
}
addCurvePointCommand::~addCurvePointCommand()
{
}
void addCurvePointCommand::redo()
{
	PointType pt=this->args.pointType;
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
		this->datamanipulator->EnterIntoChild(this->path.path.at(i));
	switch(pt)
	{
	case Plinear:
		{
			this->datamanipulator->AddLinearPoint(this->args.point);
			break;
		}
	case Psharp:
		{
			this->datamanipulator->AddSharpPoint(this->args.point,this->args.LCpoint);
			break;
		}
	case Psmooth:
		{
			this->datamanipulator->AddSmoothPoint(this->args.point,this->args.LCpoint);
			break;
		}
	case Psymmetrical:
		{
			this->datamanipulator->AddSymmetricalPoint(this->args.point,this->args.LCpoint);
			break;
		}
		}
	this->addIndex=(this->datamanipulator->PointIndexOf(this->args.point.x(),this->args.point.y()))/3;
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
	}
void addCurvePointCommand::undo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
		this->datamanipulator->EnterIntoChild(this->path.path.at(i));
	this->datamanipulator->RemovePointAt(addIndex);
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
moveCurvePointCommand::moveCurvePointCommand()
{
}
moveCurvePointCommand::~moveCurvePointCommand()
{
}
moveCurvePointCommand::moveCurvePointCommand(nodePath np,MovePointArgs a,DataManipulator* da):path(np),args(a),datamanipulator(da)
{
}
void moveCurvePointCommand::redo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	if(args.index==-3){
	int pindex=this->datamanipulator->PointIndexOf(args.oriPoint.x(),args.oriPoint.y());	
	//ePtType ept=this->datamanipulator->PointType(pindex);
	switch(pindex%3){
	case 0:
		this->datamanipulator->MoveLControlPointAt(pindex/3,args.newPoint.x(),args.newPoint.y());
		break;
	case 1:
		this->datamanipulator->MovePointAt(pindex/3,args.newPoint.x(),args.newPoint.y());
		break;
	case 2:
		this->datamanipulator->MoveRControlPointAt(pindex/3,args.newPoint.x(),args.newPoint.y());
		break;
	default:
		break;
	}}
	else
	{
		switch(args.pointtype)
		{
		case curvePoint:
			this->args.oriPoint=this->datamanipulator->PointAt(args.index);
			this->datamanipulator->MovePointAt(args.index,args.newPoint.x(),args.newPoint.y());
			break;
		case LcontrolPoint:
			this->args.oriPoint=this->datamanipulator->LControlPointAt(args.index);
			this->datamanipulator->MoveLControlPointAt(args.index,args.newPoint.x(),args.newPoint.y());
			break;
	   case RcontrolPoint:
			this->args.oriPoint=this->datamanipulator->RControlPointAt(args.index);
			this->datamanipulator->MoveRControlPointAt(args.index,args.newPoint.x(),args.newPoint.y());
			break;

		}
	}
	//this->args.oriPoint=this->datamanipulator->PointAt(pindex);
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
void moveCurvePointCommand::undo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	if(args.index==-3){
	int pindex=this->datamanipulator->PointIndexOf(args.oriPoint.x(),args.oriPoint.y());	
	//ePtType ept=this->datamanipulator->PointType(pindex);
	switch(pindex%3){
	case 0:
		this->datamanipulator->MoveLControlPointAt(pindex/3,args.oriPoint.x(),args.oriPoint.y());
		break;
	case 1:
		this->datamanipulator->MovePointAt(pindex/3,args.oriPoint.x(),args.oriPoint.y());
		break;
	case 2:
		this->datamanipulator->MoveRControlPointAt(pindex/3,args.oriPoint.x(),args.oriPoint.y());
		break;
	default:
		break;
	}}
	else
	{
		switch(args.pointtype)
		{
		case curvePoint:
			this->args.oriPoint=this->datamanipulator->PointAt(args.index);
			this->datamanipulator->MovePointAt(args.index,args.oriPoint.x(),args.oriPoint.y());
			break;
		case LcontrolPoint:
			this->args.oriPoint=this->datamanipulator->PointAt(args.index);
			this->datamanipulator->MoveLControlPointAt(args.index,args.oriPoint.x(),args.oriPoint.y());
			break;
	   case RcontrolPoint:
			this->args.oriPoint=this->datamanipulator->PointAt(args.index);
			this->datamanipulator->MoveRControlPointAt(args.index,args.oriPoint.x(),args.oriPoint.y());
			break;

		}

	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
deletePointCommand::deletePointCommand()
{
}
deletePointCommand::~deletePointCommand()
{
}
deletePointCommand::deletePointCommand (nodePath np,int dindex,DataManipulator* da):path(np),deleteIndex(dindex),datamanipulator(da)
{
}
void deletePointCommand::redo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	this->deleteType=this->datamanipulator->PointType(deleteIndex);
	deletePoint=this->datamanipulator->PointAt(deleteIndex);
	this->LCpoint=this->datamanipulator->LControlPointAt(deleteIndex);
	this->datamanipulator->RemovePointAt(deleteIndex);
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
void deletePointCommand::undo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	switch(deleteType)
	{
	case linear:
		this->datamanipulator->AddLinearPoint(deletePoint);
		break;
	case sharp:
		this->datamanipulator->AddSharpPoint(deletePoint,LCpoint);
		break;
	case smooth:
		this->datamanipulator->AddSmoothPoint(deletePoint,LCpoint);
		break;
	case symmetrical:
		this->datamanipulator->AddSymmetricalPoint(deletePoint,LCpoint);
		break;
	default:
		break;
	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
changePointTypeCommand::changePointTypeCommand()
{
}
changePointTypeCommand::~changePointTypeCommand()
{
}
changePointTypeCommand::changePointTypeCommand(nodePath np,ChangePointTypeArgs a,DataManipulator* da):path(np),args(a),datamanipulator(da)
{
}
void changePointTypeCommand::redo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	this->oldType=this->datamanipulator->PointType(args.index);
	switch(args.destType)
	{
	case Psharp:
		this->datamanipulator->ChangePointType(args.index,sharp);
		break;
	case Psmooth:
		this->datamanipulator->ChangePointType(args.index,smooth);
		break;
	case Plinear:
		this->datamanipulator->ChangePointType(args.index,linear);
		break;
	case Psymmetrical:
		this->datamanipulator->ChangePointType(args.index,symmetrical);
		break;
	default:
		break;
	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
void changePointTypeCommand::undo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	//this->oldType=this->datamanipulator->PointType(args.index);
	switch(oldType)
	{
	case Psharp:
		this->datamanipulator->ChangePointType(args.index,sharp);
		break;
	case Psmooth:
		this->datamanipulator->ChangePointType(args.index,smooth);
		break;
	case Plinear:
		this->datamanipulator->ChangePointType(args.index,linear);
		break;
	case Psymmetrical:
		this->datamanipulator->ChangePointType(args.index,symmetrical);
		break;
	default:
		break;
	}
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();

}
setGradientCommand::setGradientCommand()
{}
setGradientCommand::~setGradientCommand()
{}
setGradientCommand::setGradientCommand(nodePath np,SetGradientArgs a,DataManipulator* da):path(np),args(a),datamanipulator(da)
{}
void setGradientCommand::redo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	const QGradient* tmp=this->datamanipulator->CurrentBrush().gradient();
	oldGradient=new QGradient(*(tmp));
	if(args.gType=LinearGradient)
	{
		QLinearGradient lgradient(args.startPoint,args.endPoint);
		if(args.setColor.count()<=args.setPoint.count())
		{
			for(int i=0;i!=args.setColor.count();i++)
				lgradient.setColorAt(args.setPoint[i],args.setColor[i]);
		}
		if(args.setColor.count()>=args.setPoint.count())
		{
			for(int i=0;i!=args.setPoint.count();i++)
				lgradient.setColorAt(args.setPoint[i],args.setColor[i]);
		}
	    this->datamanipulator->CurrentBrush()=QBrush(lgradient);
	}
	else
	{
		QRadialGradient rgradient(args.centralPoint ,args.cradius,args.focusPoint,args.fradius);
		if(args.setColor.count()<=args.setPoint.count())
		{
			for(int i=0;i!=args.setColor.count();i++)
				rgradient.setColorAt(args.setPoint[i],args.setColor[i]);
		}
		if(args.setColor.count()>=args.setPoint.count())
		{
			for(int i=0;i!=args.setPoint.count();i++)
				rgradient.setColorAt(args.setPoint[i],args.setColor[i]);
		}
	    this->datamanipulator->CurrentBrush()=QBrush(rgradient);
	}
	//oldGratient=new Gradient(*((Gradient*)this->));
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
void setGradientCommand::undo()
{
	this->datamanipulator->ToRoot();
	for(int i=0;i!=this->path.path.count();i++)
	{
		this->datamanipulator->EnterIntoChild(this->path.path[i]);
	}
	this->datamanipulator->CurrentBrush()=QBrush(*(this->oldGradient));
	this->datamanipulator->EscapeToParent();
	this->datamanipulator->Update();
}
MacroCommand::MacroCommand()
{
	this->commands=QVector<QUndoCommand*>();
}
MacroCommand::~MacroCommand()
{
}
void MacroCommand::redo()
{
	for(int i=0;i!=this->commands.count();i++)
		this->commands[i]->redo();
}
void MacroCommand::undo()
{
	for(int i=0;i!=this->commands.count();i++)
		this->commands[i]->undo();
}
